package com.chezai.client.utils;

import android.text.TextUtils;

import com.orhanobut.logger.Logger;

import java.util.List;

/**
 * 立宇泰 703B 工具类
 */
public class CoreConfig {
    public static final int FILE_NORMAL = 0;
    public static final int FILE_NOT_FOUND = -1;
    public static final int FILE_CONTENT_ERROR = -2;
    public static final int SD_UMOUNT = -3;
    private static final String COREFILENAME = "/system/devnum.prop";
    private static final String TAG = "CoreConfig";
    private String coreNum;
    private String coreState;
    private String terminalType;
    private String terminalSerial;

    public CoreConfig() {
//		FileUtil.execCommand("mount -rw -o remount /dev/block/mmclk0p2 /system");
    }

    public int getCore() {
        int retval = -1;
        List<String> contents = FileUtil.readFileByLines(COREFILENAME);
        if (contents == null)
            return -3;
        if (contents.size() <= 0)
            return -1;
        String s = FileUtil.readFileByLines(COREFILENAME).get(0);
        Logger.t(TAG).i(s);
        if (TextUtils.isEmpty(s)) {
            coreNum = null;
            coreState = null;
            retval = -1;
        } else if (s.contains(" state:")) {
            String a[] = s.split(" state:");
            if (a.length == 2) {
                String tmp = a[0].trim();
                if (tmp.length() == 13) {
                    coreNum = a[0].trim();
                    coreState = a[1].trim();
                    terminalType = coreNum.substring(0, 9);
                    terminalSerial = coreNum.substring(9);
                    retval = 0;
                } else {
                    coreNum = null;
                    coreState = null;
                    retval = -2;
                }
            } else {
                coreNum = null;
                coreState = null;
                retval = -2;
            }
        }
        return retval;
    }

    public String getCoreNum() {
        return coreNum;
    }

    public String getCoreState() {
        return coreState;
    }

    public String getTerminalType() {
        return terminalType;
    }

    public String getTerminalSerial() {
        return terminalSerial;
    }
}
